package com.moli.iov.down.command.design.command.param.query.impl;

import com.moli.iov.down.command.codec.decode.bean.extend.QueryResExtendBean;
import com.moli.iov.down.command.design.command.param.query.ParamQueryCommand;
import com.moli.iov.util.ByteArrayUtil;
import org.slf4j.LoggerFactory;

/**
 * <p>
 * 蓝牙名称 解析
 * </p>
 *
 * @author: zql
 * @Date: 2019/4/26 14:20
 */
public class BluetoothNameCommand implements ParamQueryCommand {

    private static  final org.slf4j.Logger logger = LoggerFactory.getLogger(BluetoothNameCommand.class);

    /**
     * 补0
     */
    private static final String ZERO = "0";

    /**
     * 蓝牙名称 解析
     * @param queryResExtendBean
     * @param value
     * @return
     */
    @Override
    public QueryResExtendBean execute(QueryResExtendBean queryResExtendBean, byte[] value) {
        try{
            String name = ByteArrayUtil.asciiToStr(value);
            int index = name.indexOf(ZERO);
            if(index > 0){
                queryResExtendBean.setValue(name.substring(0, name.indexOf(ZERO)));
            }
            queryResExtendBean.setValue(name);
        }catch(Exception e){
            logger.error("蓝牙名称 解析 异常", e);
        }
        return queryResExtendBean;
    }
}
